#include "logInterface.h"
#include "dataBase/logRecordFunction.h"
#include "syslog.h"

void logInterfaceLogAdd(enum logClassType logClass,uint8_t logMainType, uint16_t logSubType, enum commonDataType datatype, void* pData){

    LogClassData logClassData;

    if(logMainType >= LOG_MAINTYPE_MAX || logSubType >= 3000)
    {
        syslog(LOG_WARNING, "%s: Unknown log [%d-%d]", __func__, logMainType, logSubType);
        return;
    }

    if(logClass == LOG_CLASS_SPECIAL){
        logClassData.logType = upload_log;
    }
    else{
        logClassData.logType = local_log;
    }

    logClassData.logFuncMainType = logMainType;
    logClassData.logFuncSubType = logSubType;
    logClassData.logDataType = datatype;

    switch(datatype){
        case COM_DATA_TYPE_UINT8:
            logClassData.logDataValue.uint8Value = *(uint8_t*)pData;
            break;
        case COM_DATA_TYPE_INT8:
            logClassData.logDataValue.int8Value = *(int8_t*)pData;
            break;
        case COM_DATA_TYPE_UINT16:
            logClassData.logDataValue.uint16Value = *(uint16_t*)pData;
            break;
        case COM_DATA_TYPE_INT16:
            logClassData.logDataValue.int16Value = *(int16_t*)pData;
            break;
        case COM_DATA_TYPE_UINT32:
            logClassData.logDataValue.uint32Value = *(uint32_t*)pData;
            break;
        case COM_DATA_TYPE_INT32:
            logClassData.logDataValue.int32Value = *(int32_t*)pData;
            break;
        case COM_DATA_TYPE_UINT64:
            logClassData.logDataValue.uint64Value = *(uint64_t*)pData;
            break;
        case COM_DATA_TYPE_INT64:
            logClassData.logDataValue.int64Value = *(int64_t*)pData;
            break;
        case COM_DATA_TYPE_FLOAT:
            logClassData.logDataValue.floatValue = *(float*)pData;
            break;
        default:
            break;
    }

    insertLog_db(&logClassData);

}

void logInterfaceLogClear(enum logClassType logClass){

}
